#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
#define maxn 300001
#define maxbz 20
const int INF = 1 << 30;

int n, m;
vector<pair<int, int> > conn_matrix[maxn];
struct Plan{
	int from, to, length;
}plan[maxn];
int passed[maxn];
int depth[maxn];
int parent_bz[maxn][maxbz];
int disToRoot[maxn];
int node_weight[maxn];
int dfsSeq[maxn];
int global_root;

void bz_init(){
	for (int j = 1; (1 << j) <= n; j++)
		for (int i = 1; i <= n; i++)
			parent_bz[i][j] = parent_bz[parent_bz[i][j - 1]][j - 1];
}

int tick=0;
void dfs(int u, int p, int w){
	depth[u] = depth[p] + 1;
	parent_bz[u][0] = p;
	disToRoot[u] = disToRoot[p] + w;
	node_weight[u] = w;
	dfsSeq[tick] = u;
	tick++;
	for (int i = 0; i<conn_matrix[u].size(); i++){
		int v = conn_matrix[u][i].first;
		int wv = conn_matrix[u][i].second;
		if (v != p)
			dfs(v, u, wv);
	}
}

void init(int globalroot){
	global_root = globalroot;
	dfs(global_root, 0, 0);
	bz_init();
}
	
int get_lca(int a, int b) {
	if (depth[a]>depth[b])
		swap(a, b);
	for (int i = maxbz - 1; i >= 0; i--) {
		if (depth[a]<depth[b] && depth[parent_bz[b][i]] >= depth[a])
			b = parent_bz[b][i];
	}
	if (a == b) return a;
	for (int j = maxbz - 1; j >= 0; j--) {
		if (parent_bz[a][j] != parent_bz[b][j]) {
			a = parent_bz[a][j];
			b = parent_bz[b][j];
		}
	}
	return parent_bz[a][0];
}
	
int get_lca_w(int a, int b){
	return disToRoot[a] + disToRoot[b] - 2*disToRoot[get_lca(a,b)];
}

bool check(int length) {
	memset(passed, 0, sizeof(passed));
	int maxPlan = 0, cnt = 0;
	//cnt表示大于length的计划的总数
	//maxPlan表示那个最大运输长度的计划中超出二分length部分的长度
	for (int i = 0; i < m; i++) {
		if (plan[i].length <= length) continue;
		cnt++;
		passed[plan[i].from]++;
		passed[plan[i].to]++;
		passed[get_lca(plan[i].from, plan[i].to)] -= 2;
		maxPlan = max(maxPlan, plan[i].length - length);
	}
	if (cnt == 0) return true;
	//求树上前缀和，将自己的经过次数加到父亲身上，按dfs倒序求
	for(int i=n-1; i>=0; i--){
		int u = dfsSeq[i];
		passed[parent_bz[u][0]] += passed[u];
	}
	//判断cnt与passed
	for(int i=1; i<=n; i++){
		//找出所有被不符合条件的计划都经过的边中的最大值(需要将边权转换为点权)
		if(passed[i]==cnt && node_weight[i] >= maxPlan)
			return true;
	}
	return false;
}

int main(){
	cin >> n >> m;
	for (int i = 0; i < n - 1; i++){
		int u, v, w;
		cin >> u >> v >> w;
		conn_matrix[u].push_back(make_pair(v, w));
		conn_matrix[v].push_back(make_pair(u, w));
	}
	for (int i = 0; i < m; i++){
		int u, v;
		cin >> u >> v;
		plan[i].from = u;
		plan[i].to = v;
	}

	init(1);

	for (int i = 0; i < m; i++){
		plan[i].length = get_lca_w(plan[i].from, plan[i].to);
	}

	int l=0, r=INF;
	while(l<r){
		int mid = (r+l)/2;
		if(check(mid)) r=mid;
		else l=mid+1;
	}
	cout<<l<<endl;
	
	return 0;
}